package tests;

import static org.junit.Assert.*;

import interfaces.Answer;
import interfaces.BuildGraph;

import java.util.ArrayList;

import graph.GenericGraph;
import graph.Node;
import graphAndAnswer.MultipleStartPointsAnswer;
import graphAndAnswer.MultipleStartPointsGraph;


import org.junit.Test;


import classesPERT.PERTNetwerk;

public class PERTNetwerkTEST {

	BuildGraph graphBuilder = new MultipleStartPointsGraph();
	GenericGraph testingGraph = graphBuilder.getGraph();
	Answer answer = new MultipleStartPointsAnswer();
	PERTNetwerk pertMethods = new PERTNetwerk();

	@Test
	public void testTopologicalSorting() {
		int i = 0;
		for (Node node : pertMethods.topologicalSorting(testingGraph)) {
			assertTrue(node.getName().equals(answer.getTopo(i)));
			i++;
		}
	}

	@Test
	public void testCalculateEarliest() {
		testingGraph = graphBuilder.getGraph();
		ArrayList<Node> sorted = pertMethods.topologicalSorting(testingGraph);
		testingGraph = graphBuilder.getGraph();
		pertMethods.calculateEarliest(testingGraph, sorted);
		for (Node node : testingGraph.getNodes()) {
			assertTrue("node=" + node.getName() + " failed",
					node.getEarliest() == answer.checkEarly(node.getName()));
		}
	}

	@Test
	public void testTotal() {
		testingGraph = graphBuilder.getGraph();
		ArrayList<Node> sorted = pertMethods.topologicalSorting(testingGraph);
		testingGraph = graphBuilder.getGraph();
		pertMethods.calculateEarliest(testingGraph, sorted);
		pertMethods.calculateLatest(testingGraph, sorted);
		for (Node node : testingGraph.getNodes()) {
			assertTrue("node=" + node.getName() + " failed", node.toString()
					.equals(answer.getAnswer(node.getName())));
		}
	}
}
